package com.my.util;

import java.sql.*;

public class DBCon {
    public static final String url ="jdbc:mysql://localhost:3306/db_hbook?characterEncoding=utf8";
    public static final String name="com.mysql.cj.jdbc.Driver";
    public static final String user="root";
    public static final String password="password";
    private Connection con;


public Connection getConnection(){
    try{
        Class.forName("com.mysql.cj.jdbc.Driver");
        con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_hbook?characterEncoding=utf8", "root", "password");
    }catch (ClassNotFoundException e){
        // TODO Auto-generated catch block
        e.printStackTrace();
    }catch (SQLException e){
        e.printStackTrace();
    }
    return con;
}

public static void main(String[] args) {

    DBCon db = new DBCon();
    System.out.println("con=" + db.getConnection());
    }
}

